/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bonus;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JDialog;
import javax.swing.SwingWorker;

/**
 *
 * @author Administrator
 */
public class SwingWorkerCompletionWaiter implements PropertyChangeListener {

    private JDialog dialog;

    public SwingWorkerCompletionWaiter(JDialog dialog) {
        this.dialog = dialog;
    }

    @Override
    public void propertyChange(PropertyChangeEvent event) {
        if ("state".equals(event.getPropertyName())
                && SwingWorker.StateValue.DONE == event.getNewValue()) {
            dialog.setVisible(false);
            dialog.dispose();
        }
    }
}

//JDialog dialog = new TipDialog(mainFrame, true);
//
//swingWorker.addPropertyChangeListener(new SwingWorkerCompletionWaiter(dialog));
//swingWorker.execute();
////the dialog will be visible until the SwingWorker is done
//dialog.setVisible(true);
